package com.youyi.yyviewsdklibrary;

import static com.alipay.sdk.packet.e.i;
import static com.youyi.yyviewsdklibrary.YYSDK.YToastEnum.normal;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.res.Resources;
import android.os.Handler;
import android.os.Message;
import android.text.Html;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.TextView;

import com.alipay.sdk.packet.e;
import com.bumptech.glide.request.target.ViewTarget;

import com.lkx.liandianqinew.R;
import com.youyi.yyviewsdklibrary.Bean.AppBean;
import com.youyi.yyviewsdklibrary.Bean.YYTaostBan;
import com.youyi.yyviewsdklibrary.Dialog.XPopup;
import com.youyi.yyviewsdklibrary.Dialog.core.AttachPopupView;
import com.youyi.yyviewsdklibrary.Dialog.core.BasePopupView;
import com.youyi.yyviewsdklibrary.Dialog.core.ImageViewerPopupView;
import com.youyi.yyviewsdklibrary.Dialog.core.XDialog;
import com.youyi.yyviewsdklibrary.Dialog.impl.AttachListPopupView;
import com.youyi.yyviewsdklibrary.Dialog.impl.ConfirmPopupView;
import com.youyi.yyviewsdklibrary.Dialog.interfaces.OnCancelListener;
import com.youyi.yyviewsdklibrary.Dialog.interfaces.OnConfirmListener;
import com.youyi.yyviewsdklibrary.Dialog.interfaces.OnDateAndTimeBackRange;
import com.youyi.yyviewsdklibrary.Dialog.interfaces.OnDateBack;
import com.youyi.yyviewsdklibrary.Dialog.interfaces.OnDateBackRange;
import com.youyi.yyviewsdklibrary.Dialog.interfaces.OnInputConfirmListener;
import com.youyi.yyviewsdklibrary.Dialog.interfaces.OnSelectListener;
import com.youyi.yyviewsdklibrary.Dialog.interfaces.OnSrcViewUpdateListener;
import com.youyi.yyviewsdklibrary.Dialog.interfaces.OnTimeBack;
import com.youyi.yyviewsdklibrary.Dialog.interfaces.OnViewBack;
import com.youyi.yyviewsdklibrary.Dialog.util.BackgroundExecutor;
import com.youyi.yyviewsdklibrary.Dialog.util.SmartGlideImageLoader;
import com.youyi.yyviewsdklibrary.View.MyButtomView;
import com.youyi.yyviewsdklibrary.View.MyImgColorView;
import com.youyi.yyviewsdklibrary.View.MySearchView;
import com.youyi.yyviewsdklibrary.picker.entity.DateEntity;
import com.youyi.yyviewsdklibrary.picker.entity.TimeEntity;
import com.youyi.yyviewsdklibrary.picker.widget.DateWheelLayout;
import com.youyi.yyviewsdklibrary.picker.widget.MonthWheelLayout;
import com.youyi.yyviewsdklibrary.picker.widget.TimeWheelLayout;
import es.dmoral.toasty.Toasty;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Iterator;
import java.util.List;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class YYSDK {
    private static final YYSDK ourInstance = new YYSDK();
    private AppAdapter mAppAdapter;
    private ArrayList<AppBean> mAppList;
    private Context mContext;
    private List<String> mNormalRgbList;
    private String mNowRgb;
    private List<String> mRgbList;
    private String mSearchName;

    public interface OnAppChoseListener {
        void result(boolean z, AppBean appBean);
    }

    public interface OnBottomClickListener {
        void result(boolean z, int i);
    }

    public interface OnColorListener {
        void result(boolean z, String str);
    }

    public enum YToastEnum {
        normal,
        info,
        warn,
        err,
        success
    }

    public static YYSDK getInstance() {
        return ourInstance;
    }

    private YYSDK() {
    }

    public void init(Context context) {
        this.mContext = context;
        ViewTarget.setTagId(0x7f0900ba);
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }
        Toasty.Config.getInstance().allowQueue(false).apply();
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(YYTaostBan yYTaostBan) {
        String msg = yYTaostBan.getMsg();
        YToastEnum i = yYTaostBan.getYToastEnum();
        if (i == normal) {
            Toasty.normal(this.mContext, msg, 0).show();
        } else if (i == YToastEnum.info) {
            Toasty.info(this.mContext, msg, 0).show();
        } else if (i == YToastEnum.warn) {
            Toasty.warning(this.mContext, msg, 0).show();
        } else if (i == YToastEnum.err) {
            Toasty.error(this.mContext, msg, 0).show();
        } else if (i == YToastEnum.success) {
            Toasty.success(this.mContext, msg, 0).show();
        }
    }

    public AttachPopupView showPopup(Context context, String[] strArr, int[] iArr, View view, OnSelectListener onSelectListener) {
        AttachListPopupView contentGravity = new XPopup.Builder(context).hasShadowBg(true).isClickThrough(false).isDestroyOnDismiss(true).atView(view).asAttachList(strArr, iArr, onSelectListener, 0, 0).setContentGravity(16);
        contentGravity.show();
        return contentGravity;
    }

    public BasePopupView showSure(Context context, String str, String str2, String str3, String str4, boolean z, boolean z2, OnConfirmListener onConfirmListener, OnCancelListener onCancelListener) {
        ConfirmPopupView asConfirm = new XPopup.Builder(context).hasShadowBg(true).isDestroyOnDismiss(true).dismissOnTouchOutside(Boolean.valueOf(z)).asConfirm(str, str2, z2, str3, str4, onConfirmListener, onCancelListener, false);
        asConfirm.show();
        return asConfirm;
    }

    public BasePopupView showEdit(Context context, String str, String str2, String str3, OnInputConfirmListener onInputConfirmListener) {
        return new XPopup.Builder(context).hasStatusBarShadow(false).isDestroyOnDismiss(true).autoOpenSoftInput(true).isDarkTheme(false).isViewMode(true).asInputConfirm(str, "", str3, str2, onInputConfirmListener).show();
    }

    public BasePopupView showBottomListMenu(Context context, String str, String[] strArr, OnSelectListener onSelectListener) {
        return new XPopup.Builder(context).isDarkTheme(false).hasShadowBg(true).asBottomList(str, strArr, onSelectListener).show();
    }

    public BasePopupView showBottomListMenuByChose(Context context, String str, String[] strArr, int i, OnSelectListener onSelectListener) {
        return new XPopup.Builder(context).isDarkTheme(false).hasShadowBg(true).asBottomList(str, strArr, (int[]) null, i, onSelectListener).show();
    }

    public BasePopupView showBigImg(Context context, ImageView imageView, Object obj, boolean z) {
        return new XPopup.Builder(context).asImageViewer(imageView, obj, z, new SmartGlideImageLoader()).show();
    }

    public BasePopupView showBigImgList(Context context, ImageView imageView, List<Object> list, int i, boolean z) {
        return new XPopup.Builder(context).asImageViewer(imageView, i, list, true, false, -1, -1, -1, z, -16777216, new OnSrcViewUpdateListener() {
            /* class com.youyi.yyviewsdklibrary.YYSDK.AnonymousClass1 */

            @Override // com.youyi.yyviewsdklibrary.Dialog.interfaces.OnSrcViewUpdateListener
            public void onSrcViewUpdate(ImageViewerPopupView imageViewerPopupView, int i) {
            }
        }, new SmartGlideImageLoader(), null).show();
    }

    public BasePopupView showLoading(Context context, String str) {
        return new XPopup.Builder(context).dismissOnBackPressed(false).isLightNavigationBar(true).isDarkTheme(true).isViewMode(false).asLoading(str).show();
    }

    public void showDefine(Context context, boolean z, boolean z2, int i, OnViewBack onViewBack) {
        XPopup.showDefine(context, z ? XPopup.DirecEnum.CENTER : XPopup.DirecEnum.BOTTOM, z2, i, onViewBack);
    }

    public void showDefineAttachBottom(Context context, View view, boolean z, int i, OnViewBack onViewBack) {
        XPopup.showDefineAttachBottom(context, view, z, i, onViewBack);
    }

    public static void toast(YToastEnum yToastEnum, String str) {
        EventBus.getDefault().post(new YYTaostBan(yToastEnum, str));
    }

    public void choseDateRange(Context context, boolean z, boolean z2, final int i, final int i2, final int i3, final int i4, final int i5, final int i6, final OnDateBackRange onDateBackRange) {
        XPopup.showDefine(context, z ? XPopup.DirecEnum.CENTER : XPopup.DirecEnum.BOTTOM, z2, R.layout._y_chose_date_range, new OnViewBack() {

            @Override // com.youyi.yyviewsdklibrary.Dialog.interfaces.OnViewBack
            public void result(final XDialog xDialog, View view) {
                int i = 0;
                int i2 = 0;
                int i3 = 0;
                int i4 = 0;
                MyButtomView myButtomView = (MyButtomView) view.findViewById(R.id.id_my_bottom);
                final DateWheelLayout dateWheelLayout = (DateWheelLayout) view.findViewById(R.id.id_date_picker_start);
                final DateWheelLayout dateWheelLayout2 = (DateWheelLayout) view.findViewById(R.id.id_date_picker_end);
                Calendar instance = Calendar.getInstance();
                int i5 = instance.get(1);
                int i6 = instance.get(2) + 1;
                int i7 = instance.get(5);
                DateEntity target = DateEntity.target(i5 - 10, 1, 1);
                DateEntity target2 = DateEntity.target(i5 + 10, 12, 31);
                DateEntity target3 = DateEntity.target(i5, i6, i7);
                int i8 = i;
                if (!(i8 == 0 || (i3 = i2) == 0 || (i4 = i3) == 0)) {
                    target3 = DateEntity.target(i8, i3, i4);
                }
                DateEntity target4 = DateEntity.target(i5, i6, i7);
                int i9 = i4;
                if (!(i9 == 0 || (i = i5) == 0 || (i2 = i6) == 0)) {
                    target4 = DateEntity.target(i9, i, i2);
                }
                dateWheelLayout.setRange(target, target2, target3);
                dateWheelLayout2.setRange(target, target2, target4);
                myButtomView.setOnItemClickListener(new MyButtomView.onItemClickListener() {
                    /* class com.youyi.yyviewsdklibrary.YYSDK.AnonymousClass2.AnonymousClass1 */

                    @Override // com.youyi.yyviewsdklibrary.View.MyButtomView.onItemClickListener
                    public void onCancelClick(View view) {
                        xDialog.dismiss();
                    }

                    @Override // com.youyi.yyviewsdklibrary.View.MyButtomView.onItemClickListener
                    public void onSureClick(View view) {
                        if (onDateBackRange != null) {
                            onDateBackRange.result(dateWheelLayout.getSelectedYear(), dateWheelLayout.getSelectedMonth(), dateWheelLayout.getSelectedDay(), dateWheelLayout2.getSelectedYear(), dateWheelLayout2.getSelectedMonth(), dateWheelLayout2.getSelectedDay());
                        }
                        xDialog.dismiss();
                    }
                });
            }
        });
    }

    public void choseDateAndTimeRange(Context context, final String str, boolean z, boolean z2, final int i, final int i2, final int i3, final int i4, final int i5, final int i6, final OnDateAndTimeBackRange onDateAndTimeBackRange) {
        XPopup.showDefine(context, z ? XPopup.DirecEnum.CENTER : XPopup.DirecEnum.BOTTOM, z2, R.layout._y_chose_date_and_time_range, new OnViewBack() {
            /* class com.youyi.yyviewsdklibrary.YYSDK.AnonymousClass3 */

            @Override // com.youyi.yyviewsdklibrary.Dialog.interfaces.OnViewBack
            public void result(final XDialog xDialog, View view) {
                int i = 0;
                int i2 = 0;
                MyButtomView myButtomView = (MyButtomView) view.findViewById(R.id.id_my_bottom);
                final DateWheelLayout dateWheelLayout = (DateWheelLayout) view.findViewById(R.id.id_date_picker_start);
                final TimeWheelLayout timeWheelLayout = (TimeWheelLayout) view.findViewById(R.id.id_time_picker_start);
                Calendar instance = Calendar.getInstance();
                boolean z = true;
                int i3 = instance.get(1);
                int i4 = instance.get(5);
                DateEntity target = DateEntity.target(i3 - 10, 1, 1);
                DateEntity target2 = DateEntity.target(i3 + 10, 12, 31);
                DateEntity target3 = DateEntity.target(i3, instance.get(2) + 1, i4);
                int i5 = i;
                if (!(i5 == 0 || (i = i2) == 0 || (i2 = i3) == 0)) {
                    target3 = DateEntity.target(i5, i, i2);
                }
                myButtomView.setTitle(str);
                int i6 = instance.get(11);
                int i7 = instance.get(12);
                int i8 = instance.get(13);
                int i9 = i4;
                if (i9 != 0) {
                    int i10 = i5;
                    boolean z2 = i10 != 0;
                    int i11 = i6;
                    if (i11 == 0) {
                        z = false;
                    }
                    if (z && z2) {
                        i6 = i9;
                        i7 = i10;
                        i8 = i11;
                    }
                }
                timeWheelLayout.setDefaultValue(TimeEntity.target(i6, i7, i8));
                dateWheelLayout.setRange(target, target2, target3);
                myButtomView.setOnItemClickListener(new MyButtomView.onItemClickListener() {
                    /* class com.youyi.yyviewsdklibrary.YYSDK.AnonymousClass3.AnonymousClass1 */

                    @Override // com.youyi.yyviewsdklibrary.View.MyButtomView.onItemClickListener
                    public void onCancelClick(View view) {
                        xDialog.dismiss();
                    }

                    @Override // com.youyi.yyviewsdklibrary.View.MyButtomView.onItemClickListener
                    public void onSureClick(View view) {
                        if (onDateAndTimeBackRange != null) {
                            onDateAndTimeBackRange.result(dateWheelLayout.getSelectedYear(), dateWheelLayout.getSelectedMonth(), dateWheelLayout.getSelectedDay(), timeWheelLayout.getSelectedHour(), timeWheelLayout.getSelectedMinute(), timeWheelLayout.getSelectedSecond());
                        }
                        xDialog.dismiss();
                    }
                });
            }
        });
    }

    public void choseDate(Context context, boolean z, boolean z2, final int i, final int i2, final int i3, final OnDateBack onDateBack) {
        XPopup.showDefine(context, z ? XPopup.DirecEnum.CENTER : XPopup.DirecEnum.BOTTOM, z2, R.layout._y_chose_date_one, new OnViewBack() {
            /* class com.youyi.yyviewsdklibrary.YYSDK.AnonymousClass4 */

            @Override // com.youyi.yyviewsdklibrary.Dialog.interfaces.OnViewBack
            public void result(final XDialog xDialog, View view) {
                int i = 0;
                int i2 = 0;
                MyButtomView myButtomView = (MyButtomView) view.findViewById(R.id.id_my_bottom);
                final DateWheelLayout dateWheelLayout = (DateWheelLayout) view.findViewById(R.id.id_date_picker_start);
                Calendar instance = Calendar.getInstance();
                int i3 = instance.get(1);
                int i4 = instance.get(5);
                DateEntity target = DateEntity.target(i3 - 10, 1, 1);
                DateEntity target2 = DateEntity.target(i3 + 10, 12, 31);
                DateEntity target3 = DateEntity.target(i3, instance.get(2) + 1, i4);
                int i5 = i;
                if (!(i5 == 0 || (i = i2) == 0 || (i2 = i3) == 0)) {
                    target3 = DateEntity.target(i5, i, i2);
                }
                dateWheelLayout.setRange(target, target2, target3);
                myButtomView.setOnItemClickListener(new MyButtomView.onItemClickListener() {
                    /* class com.youyi.yyviewsdklibrary.YYSDK.AnonymousClass4.AnonymousClass1 */

                    @Override // com.youyi.yyviewsdklibrary.View.MyButtomView.onItemClickListener
                    public void onCancelClick(View view) {
                        xDialog.dismiss();
                    }

                    @Override // com.youyi.yyviewsdklibrary.View.MyButtomView.onItemClickListener
                    public void onSureClick(View view) {
                        if (onDateBack != null) {
                            onDateBack.result(dateWheelLayout.getSelectedYear(), dateWheelLayout.getSelectedMonth(), dateWheelLayout.getSelectedDay());
                        }
                        xDialog.dismiss();
                    }
                });
            }
        });
    }

    public void choseMonth(Context context, final boolean z, boolean z2, boolean z3, final int i, final int i2, final int i3, final OnDateBack onDateBack) {
        XPopup.showDefine(context, z2 ? XPopup.DirecEnum.CENTER : XPopup.DirecEnum.BOTTOM, z3, R.layout._y_chose_date_month, new OnViewBack() {
            /* class com.youyi.yyviewsdklibrary.YYSDK.AnonymousClass5 */

            @Override // com.youyi.yyviewsdklibrary.Dialog.interfaces.OnViewBack
            public void result(final XDialog xDialog, View view) {
                int i = 0;
                int i2 = 0;
                MyButtomView myButtomView = (MyButtomView) view.findViewById(R.id.id_my_bottom);
                final MonthWheelLayout monthWheelLayout = (MonthWheelLayout) view.findViewById(R.id.id_date_picker_start);
                monthWheelLayout.setIsOld(z);
                Calendar instance = Calendar.getInstance();
                int i3 = instance.get(1);
                int i4 = instance.get(5);
                DateEntity target = DateEntity.target(i3 - 10, 1, 1);
                DateEntity target2 = DateEntity.target(i3 + 10, 12, 31);
                DateEntity target3 = DateEntity.target(i3, instance.get(2) + 1, i4);
                int i5 = i;
                if (!(i5 == 0 || (i = i2) == 0 || (i2 = i3) == 0)) {
                    target3 = DateEntity.target(i5, i, i2);
                }
                monthWheelLayout.setRange(target, target2, target3);
                myButtomView.setOnItemClickListener(new MyButtomView.onItemClickListener() {
                    /* class com.youyi.yyviewsdklibrary.YYSDK.AnonymousClass5.AnonymousClass1 */

                    @Override // com.youyi.yyviewsdklibrary.View.MyButtomView.onItemClickListener
                    public void onCancelClick(View view) {
                        xDialog.dismiss();
                    }

                    @Override // com.youyi.yyviewsdklibrary.View.MyButtomView.onItemClickListener
                    public void onSureClick(View view) {
                        if (onDateBack != null) {
                            onDateBack.result(monthWheelLayout.getSelectedYear(), monthWheelLayout.getSelectedMonth(), monthWheelLayout.getSelectedDay());
                        }
                        xDialog.dismiss();
                    }
                });
            }
        });
    }

    public void choseTime(Context context, final String str, boolean z, boolean z2, final int i, final int i2, final int i3, final OnTimeBack onTimeBack) {
        XPopup.showDefine(context, z ? XPopup.DirecEnum.CENTER : XPopup.DirecEnum.BOTTOM, z2, R.layout._y_chose_time_one, new OnViewBack() {
            /* class com.youyi.yyviewsdklibrary.YYSDK.AnonymousClass6 */

            @Override // com.youyi.yyviewsdklibrary.Dialog.interfaces.OnViewBack
            public void result(final XDialog xDialog, View view) {
                MyButtomView myButtomView = (MyButtomView) view.findViewById(R.id.id_my_bottom);
                final TimeWheelLayout timeWheelLayout = (TimeWheelLayout) view.findViewById(R.id.id_time_picker_start);
                Calendar instance = Calendar.getInstance();
                myButtomView.setTitle(str);
                int i = instance.get(11);
                int i2 = instance.get(12);
                int i3 = instance.get(13);
                int i4 = i;
                if (i4 != 0) {
                    int i5 = i2;
                    boolean z = true;
                    boolean z2 = i5 != 0;
                    int i6 = i3;
                    if (i6 == 0) {
                        z = false;
                    }
                    if (z && z2) {
                        i = i4;
                        i2 = i5;
                        i3 = i6;
                    }
                }
                timeWheelLayout.setDefaultValue(TimeEntity.target(i, i2, i3));
                myButtomView.setOnItemClickListener(new MyButtomView.onItemClickListener() {
                    /* class com.youyi.yyviewsdklibrary.YYSDK.AnonymousClass6.AnonymousClass1 */

                    @Override // com.youyi.yyviewsdklibrary.View.MyButtomView.onItemClickListener
                    public void onCancelClick(View view) {
                        xDialog.dismiss();
                    }

                    @Override // com.youyi.yyviewsdklibrary.View.MyButtomView.onItemClickListener
                    public void onSureClick(View view) {
                        if (onTimeBack != null) {
                            onTimeBack.result(timeWheelLayout.getSelectedHour(), timeWheelLayout.getSelectedMinute(), timeWheelLayout.getSelectedSecond());
                        }
                        xDialog.dismiss();
                    }
                });
            }
        });
    }

    public void choseColor(final Context context, String str, List<String> list, final OnColorListener onColorListener) {
        this.mNormalRgbList = new ArrayList();
        this.mNowRgb = str;
        if (!TextUtils.isEmpty(str)) {
            this.mNowRgb = this.mNowRgb.toUpperCase();
        }
        if (list == null) {
            this.mNormalRgbList.add("#1E90FF");
            this.mNormalRgbList.add("#EE82EE");
            this.mNormalRgbList.add("#4169E1");
            this.mNormalRgbList.add("#00BFFF");
            this.mNormalRgbList.add("#2E8B57");
            this.mNormalRgbList.add("#F08080");
            this.mNormalRgbList.add("#FFA07A");
            this.mNormalRgbList.add("#AFEEEE");
            this.mNormalRgbList.add("#BC8F8F");
            this.mNormalRgbList.add("#BA55D3");
            this.mNormalRgbList.add("#5F9EA0");
            this.mNormalRgbList.add("#483D8B");
            this.mNormalRgbList.add("#D2691E");
            this.mNormalRgbList.add("#3CB371");
            this.mNormalRgbList.add("#87CEFA");
            this.mNormalRgbList.add("#666666");
            this.mNormalRgbList.add("#ff9700");
            this.mNormalRgbList.add("#ff0000");
            this.mNormalRgbList.add("#009f64");
            this.mNormalRgbList.add("#2dc2ea");
            this.mNormalRgbList.add("#4bebc9");
            this.mNormalRgbList.add("#72a3ff");
            this.mNormalRgbList.add("#8b73ff");
            this.mNormalRgbList.add("#3af1c5");
            this.mNormalRgbList.add("#6c7dff");
        } else {
            this.mNormalRgbList = list;
        }
        if (TextUtils.isEmpty(this.mNowRgb)) {
            this.mNowRgb = this.mNormalRgbList.get(0);
        }
        showDefine(context, false, true, R.layout._y_chose_color_view, new OnViewBack() {
            /* class com.youyi.yyviewsdklibrary.YYSDK.AnonymousClass7 */

            @Override // com.youyi.yyviewsdklibrary.Dialog.interfaces.OnViewBack
            public void result(final XDialog xDialog, View view) {
                YYSDK yysdk = YYSDK.this;
                ((GridView) view.findViewById(R.id.id_color_gridview)).setAdapter((ListAdapter) new ColorAdatper(context, xDialog, yysdk.mNormalRgbList, onColorListener));
                ((TextView) view.findViewById(R.id.tv_sure)).setOnClickListener(new View.OnClickListener() {
                    /* class com.youyi.yyviewsdklibrary.YYSDK.AnonymousClass7.AnonymousClass1 */

                    public void onClick(View view) {
                        xDialog.dismiss();
                        if (!TextUtils.isEmpty(YYSDK.this.mNowRgb)) {
                            if (onColorListener != null) {
                                onColorListener.result(true, YYSDK.this.mNowRgb);
                            }
                        } else if (onColorListener != null) {
                            onColorListener.result(false, null);
                        }
                    }
                });
                ((ImageView) view.findViewById(R.id.tv_cancel)).setOnClickListener(new View.OnClickListener() {
                    /* class com.youyi.yyviewsdklibrary.YYSDK.AnonymousClass7.AnonymousClass2 */

                    public void onClick(View view) {
                        xDialog.dismiss();
                        if (onColorListener != null) {
                            onColorListener.result(false, null);
                        }
                    }
                });
            }
        });
    }

    public class ColorAdatper extends BaseAdapter {
        private List<String> mColorList;
        private Context mContext;
        private XDialog mDialog;
        private OnColorListener mOnColorListener;

        public Object getItem(int i) {
            return null;
        }

        public long getItemId(int i) {
            return 0;
        }

        public ColorAdatper(Context context, XDialog xDialog, List<String> list, OnColorListener onColorListener) {
            this.mContext = context;
            this.mDialog = xDialog;
            this.mColorList = list;
            this.mOnColorListener = onColorListener;
        }

        public int getCount() {
            return this.mColorList.size();
        }

        public View getView(int i, View view, ViewGroup viewGroup) {
            View inflate = View.inflate(this.mContext, R.layout._y_item_chose_color_view, null);
            MyImgColorView myImgColorView = (MyImgColorView) inflate.findViewById(R.id.id_color_view);
            final String upperCase = this.mColorList.get(i).toUpperCase();
            myImgColorView.setColorFilter(upperCase);
            if (TextUtils.isEmpty(YYSDK.this.mNowRgb)) {
                myImgColorView.setCheck(false);
            } else if (upperCase.equals(YYSDK.this.mNowRgb)) {
                myImgColorView.setCheck(true);
            } else {
                myImgColorView.setCheck(false);
            }
            myImgColorView.setOnItemClickListener(new MyImgColorView.onItemClickListener() {
                /* class com.youyi.yyviewsdklibrary.YYSDK.ColorAdatper.AnonymousClass1 */

                @Override // com.youyi.yyviewsdklibrary.View.MyImgColorView.onItemClickListener
                public void onClick(boolean z) {
                    YYSDK.this.mNowRgb = upperCase;
                    ColorAdatper.this.notifyDataSetChanged();
                    ColorAdatper.this.mDialog.dismiss();
                    if (ColorAdatper.this.mOnColorListener != null) {
                        ColorAdatper.this.mOnColorListener.result(true, YYSDK.this.mNowRgb);
                    }
                }
            });
            return inflate;
        }
    }

    public void choseAPP(final Context context, final String str, final OnAppChoseListener onAppChoseListener) {
        showDefine(context, false, false, R.layout._y_buttom_chose_app, new OnViewBack() {
            /* class com.youyi.yyviewsdklibrary.YYSDK.AnonymousClass8 */

            @Override // com.youyi.yyviewsdklibrary.Dialog.interfaces.OnViewBack
            public void result(final XDialog xDialog, View view) {
                YYSDK yysdk = YYSDK.this;
                yysdk.setTopMargin(view, yysdk.getStatusBarHeight(context));
                final TextView textView = (TextView) view.findViewById(R.id.id_waiting);
                final GridView gridView = (GridView) view.findViewById(R.id.id_gridview);
                final MySearchView mySearchView = (MySearchView) view.findViewById(R.id.id_search_view);
                textView.setVisibility(View.VISIBLE);
                gridView.setVisibility(View.GONE);
                final Handler handler = new Handler(new Handler.Callback() {
                    /* class com.youyi.yyviewsdklibrary.YYSDK.AnonymousClass8.AnonymousClass1 */

                    public boolean handleMessage(Message message) {
                        if (message.what == 342) {
                            textView.setVisibility(View.GONE);
                            gridView.setVisibility(View.VISIBLE);
                            YYSDK.this.mAppAdapter = new AppAdapter(context, xDialog, YYSDK.this.mAppList, onAppChoseListener);
                            gridView.setAdapter((ListAdapter) YYSDK.this.mAppAdapter);
                        }
                        return false;
                    }
                });
                ((RadioButton) view.findViewById(R.id._bt_all)).setOnClickListener(new View.OnClickListener() {
                    /* class com.youyi.yyviewsdklibrary.YYSDK.AnonymousClass8.AnonymousClass2 */

                    public void onClick(View view) {
                        mySearchView.setText("");
                        YYSDK.this.mAppAdapter = new AppAdapter(context, xDialog, YYSDK.this.mAppList, onAppChoseListener);
                        gridView.setAdapter((ListAdapter) YYSDK.this.mAppAdapter);
                    }
                });
                ((RadioButton) view.findViewById(R.id._bt_user)).setOnClickListener(new View.OnClickListener() {
                    /* class com.youyi.yyviewsdklibrary.YYSDK.AnonymousClass8.AnonymousClass3 */

                    public void onClick(View view) {
                        mySearchView.setText("");
                        ArrayList arrayList = new ArrayList();
                        Iterator it = YYSDK.this.mAppList.iterator();
                        while (it.hasNext()) {
                            AppBean appBean = (AppBean) it.next();
                            if (!appBean.isSys()) {
                                arrayList.add(appBean);
                            }
                        }
                        YYSDK.this.mAppAdapter = new AppAdapter(context, xDialog, arrayList, onAppChoseListener);
                        gridView.setAdapter((ListAdapter) YYSDK.this.mAppAdapter);
                    }
                });
                ((RadioButton) view.findViewById(R.id._bt_sys)).setOnClickListener(new View.OnClickListener() {
                    /* class com.youyi.yyviewsdklibrary.YYSDK.AnonymousClass8.AnonymousClass4 */

                    public void onClick(View view) {
                        mySearchView.setText("");
                        ArrayList arrayList = new ArrayList();
                        Iterator it = YYSDK.this.mAppList.iterator();
                        while (it.hasNext()) {
                            AppBean appBean = (AppBean) it.next();
                            if (appBean.isSys()) {
                                arrayList.add(appBean);
                            }
                        }
                        YYSDK.this.mAppAdapter = new AppAdapter(context, xDialog, arrayList, onAppChoseListener);
                        gridView.setAdapter((ListAdapter) YYSDK.this.mAppAdapter);
                    }
                });
                mySearchView.setOnTextChangeListener(new MySearchView.OnTextChangeListener() {
                    /* class com.youyi.yyviewsdklibrary.YYSDK.AnonymousClass8.AnonymousClass5 */

                    @Override // com.youyi.yyviewsdklibrary.View.MySearchView.OnTextChangeListener
                    public void onclick(String str) {
                    }

                    @Override // com.youyi.yyviewsdklibrary.View.MySearchView.OnTextChangeListener
                    public void change(String str) {
                        YYSDK.this.mSearchName = str;
                        if (!TextUtils.isEmpty(YYSDK.this.mSearchName)) {
                            ArrayList arrayList = new ArrayList();
                            if (YYSDK.this.mAppList != null && YYSDK.this.mAppList.size() > 0) {
                                Iterator it = YYSDK.this.mAppList.iterator();
                                while (it.hasNext()) {
                                    AppBean appBean = (AppBean) it.next();
                                    if (appBean.getAppName().contains(YYSDK.this.mSearchName) || appBean.getAppName().equals(YYSDK.this.mSearchName)) {
                                        arrayList.add(appBean);
                                    }
                                }
                                if (YYSDK.this.mAppAdapter != null) {
                                    YYSDK.this.mAppAdapter.setData(arrayList, YYSDK.this.mSearchName);
                                }
                            }
                        } else if (YYSDK.this.mAppAdapter != null) {
                            YYSDK.this.mAppAdapter.setData(YYSDK.this.mAppList, null);
                        }
                    }
                });
                BackgroundExecutor.execute(new Runnable() {
                    /* class com.youyi.yyviewsdklibrary.YYSDK.AnonymousClass8.AnonymousClass6 */

                    public void run() {
                        YYSDK.this.mAppList = YYSDK.getAllApp(context);
                        handler.sendEmptyMessage(342);
                    }
                });
                MyButtomView myButtomView = (MyButtomView) view.findViewById(R.id.id_my_buttomview);
                myButtomView.setTitle(str);
                myButtomView.setOnItemClickListener(new MyButtomView.onItemClickListener() {
                    /* class com.youyi.yyviewsdklibrary.YYSDK.AnonymousClass8.AnonymousClass7 */

                    @Override // com.youyi.yyviewsdklibrary.View.MyButtomView.onItemClickListener
                    public void onSureClick(View view) {
                    }

                    @Override // com.youyi.yyviewsdklibrary.View.MyButtomView.onItemClickListener
                    public void onCancelClick(View view) {
                        xDialog.dismiss();
                        if (onAppChoseListener != null) {
                            onAppChoseListener.result(false, null);
                        }
                    }
                });
            }
        });
    }

    public int getStatusBarHeight(Context context) {
        int identifier = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (identifier > 0) {
            return context.getResources().getDimensionPixelSize(identifier);
        }
        return (int) TypedValue.applyDimension(1, (float) 24, Resources.getSystem().getDisplayMetrics());
    }

    public void setTopMargin(View view, int i) {
        try {
            ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
            if (marginLayoutParams != null) {
                marginLayoutParams.setMargins(marginLayoutParams.leftMargin, i, marginLayoutParams.rightMargin, marginLayoutParams.bottomMargin);
                view.setLayoutParams(marginLayoutParams);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /* access modifiers changed from: private */
    public class AppAdapter extends BaseAdapter {
        Context mContext;
        XDialog mDialog;
        List<AppBean> mList;
        OnAppChoseListener mOnAppChoseListener;

        public Object getItem(int i) {
            return null;
        }

        public long getItemId(int i) {
            return 0;
        }

        public AppAdapter(Context context, XDialog xDialog, List<AppBean> list, OnAppChoseListener onAppChoseListener) {
            this.mContext = context;
            this.mList = list;
            this.mDialog = xDialog;
            this.mOnAppChoseListener = onAppChoseListener;
        }

        public int getCount() {
            return this.mList.size();
        }

        public View getView(int i, View view, ViewGroup viewGroup) {
            View inflate = View.inflate(this.mContext, R.layout._x_item_app, null);
            TextView textView = (TextView) inflate.findViewById(R.id.id_name);
            final AppBean appBean = this.mList.get(i);
            ((ImageView) inflate.findViewById(R.id.id_icon)).setImageDrawable(appBean.getAppIcon());
            String appName = appBean.getAppName();
            if (TextUtils.isEmpty(YYSDK.this.mSearchName)) {
                textView.setText(appName);
            } else {
                String str = YYSDK.this.mSearchName;
                textView.setText(Html.fromHtml(appName.replace(str, "<font color='#FF0000'>" + YYSDK.this.mSearchName + "</font>")));
            }
            inflate.setOnClickListener(new View.OnClickListener() {
                /* class com.youyi.yyviewsdklibrary.YYSDK.AppAdapter.AnonymousClass1 */

                public void onClick(View view) {
                    AppAdapter.this.mDialog.dismiss();
                    if (AppAdapter.this.mOnAppChoseListener != null) {
                        AppAdapter.this.mOnAppChoseListener.result(true, appBean);
                    }
                }
            });
            return inflate;
        }

        public void setData(List<AppBean> list, String str) {
            this.mList = list;
            YYSDK.this.mSearchName = str;
            notifyDataSetChanged();
        }
    }

    public static ArrayList<AppBean> getAllApp00(Context context) {
        ArrayList<AppBean> arrayList = new ArrayList<>();
        for (ApplicationInfo applicationInfo : context.getPackageManager().getInstalledApplications(128)) {
            PackageInfo packageInfo = PackageUtils.getPackageInfo(applicationInfo.packageName, context);
            arrayList.add(new AppBean(packageInfo.applicationInfo.loadLabel(context.getPackageManager()).toString(), packageInfo.packageName, packageInfo.versionName, packageInfo.versionCode, packageInfo.applicationInfo.loadIcon(context.getPackageManager()), packageInfo.applicationInfo.uid, (packageInfo.applicationInfo.flags & 1) > 0));
        }
        return arrayList;
    }

    public static ArrayList<AppBean> getAllApp(Context context) {
        ArrayList<AppBean> arrayList = new ArrayList<>();
        List<PackageInfo> installedPackages = context.getPackageManager().getInstalledPackages(0);
        for (int i = 0; i < installedPackages.size(); i++) {
            PackageInfo packageInfo = installedPackages.get(i);
            arrayList.add(new AppBean(packageInfo.applicationInfo.loadLabel(context.getPackageManager()).toString(), packageInfo.packageName, packageInfo.versionName, packageInfo.versionCode, packageInfo.applicationInfo.loadIcon(context.getPackageManager()), packageInfo.applicationInfo.uid, (packageInfo.applicationInfo.flags & 1) > 0));
        }
        return arrayList;
    }

    public static ArrayList<AppBean> getAllApp(Context context, APPType aPPType) {
        ArrayList<AppBean> arrayList = new ArrayList<>();
        for (PackageInfo packageInfo : context.getPackageManager().getInstalledPackages(0)) {
            AppBean appBean = new AppBean(packageInfo.applicationInfo.loadLabel(context.getPackageManager()).toString(), packageInfo.packageName, packageInfo.versionName, packageInfo.versionCode, packageInfo.applicationInfo.loadIcon(context.getPackageManager()), packageInfo.applicationInfo.uid, (packageInfo.applicationInfo.flags & 1) > 0);
            int i = aPPType.ordinal();
            if (i == 1) {
                arrayList.add(appBean);
            } else if (i != 2) {
                if ((packageInfo.applicationInfo.flags & 1) <= 0) {
                    arrayList.add(appBean);
                }
            } else if ((packageInfo.applicationInfo.flags & 1) > 0) {
                arrayList.add(appBean);
            }
        }
        return arrayList;
    }

    public enum APPType {
        ALL(0),
        SYSTEM(1),
        USER(2);
        
        private int flag;

        private APPType(int i) {
            this.flag = i;
        }

        public int getFlag() {
            return this.flag;
        }

        public void setFlag(int i) {
            this.flag = i;
        }
    }

    public void showDefineBottomList(final Context context, boolean z, final String str, final List<String> list, final OnBottomClickListener onBottomClickListener) {
        showDefine(context, false, z, R.layout._define_bottom_list, new OnViewBack() {
            /* class com.youyi.yyviewsdklibrary.YYSDK.AnonymousClass9 */

            @Override // com.youyi.yyviewsdklibrary.Dialog.interfaces.OnViewBack
            public void result(final XDialog xDialog, View view) {
                ((ListView) view.findViewById(R.id.id_listview)).setAdapter((ListAdapter) new MyBoAdapter(context, xDialog, list, str, onBottomClickListener));
                ((TextView) view.findViewById(R.id.tv_cancel)).setOnClickListener(new View.OnClickListener() {
                    /* class com.youyi.yyviewsdklibrary.YYSDK.AnonymousClass9.AnonymousClass1 */

                    public void onClick(View view) {
                        xDialog.dismiss();
                        if (onBottomClickListener != null) {
                            onBottomClickListener.result(false, 0);
                        }
                    }
                });
            }
        });
    }

    public class MyBoAdapter extends BaseAdapter {
        String mChose;
        Context mContext;
        List<String> mList;
        OnBottomClickListener mOnBottomClickListener;
        XDialog mxDialog;

        public Object getItem(int i) {
            return null;
        }

        public long getItemId(int i) {
            return 0;
        }

        public MyBoAdapter(Context context, XDialog xDialog, List<String> list, String str, OnBottomClickListener onBottomClickListener) {
            this.mContext = context;
            this.mxDialog = xDialog;
            this.mList = list;
            this.mChose = str;
            this.mOnBottomClickListener = onBottomClickListener;
        }

        public int getCount() {
            return this.mList.size();
        }

        public View getView(final int i, View view, ViewGroup viewGroup) {
            View inflate = View.inflate(this.mContext, R.layout._item_bottom_text, null);
            ImageView imageView = (ImageView) inflate.findViewById(R.id.iv_chose);
            final String str = this.mList.get(i);
            ((TextView) inflate.findViewById(R.id.tv_text)).setText(str);
            if (TextUtils.isEmpty(this.mChose)) {
                imageView.setVisibility(View.GONE);
            } else if (this.mChose.equals(str)) {
                imageView.setVisibility(View.VISIBLE);
            } else {
                imageView.setVisibility(View.GONE);
            }
            inflate.setOnClickListener(new View.OnClickListener() {
                /* class com.youyi.yyviewsdklibrary.YYSDK.MyBoAdapter.AnonymousClass1 */

                public void onClick(View view) {
                    MyBoAdapter.this.mxDialog.dismiss();
                    MyBoAdapter.this.mChose = str;
                    if (MyBoAdapter.this.mOnBottomClickListener != null) {
                        MyBoAdapter.this.mOnBottomClickListener.result(true, i);
                    }
                }
            });
            return inflate;
        }
    }

    public boolean isRightSign(SignEnum signEnum) {
        Context context = this.mContext;
        if (context == null || !getSignature(context).toLowerCase().equals(signEnum.getSign())) {
            return false;
        }
        return true;
    }

    private static String getSignature(Context context) {
        try {
            return encryptionMD5(context.getPackageManager().getPackageInfo(context.getPackageName(), 64).signatures[0].toByteArray());
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }

    private static String encryptionMD5(byte[] bArr) {
        StringBuffer stringBuffer = new StringBuffer();
        try {
            MessageDigest instance = MessageDigest.getInstance("MD5");
            instance.reset();
            instance.update(bArr);
            byte[] digest = instance.digest();
            for (int i = 0; i < digest.length; i++) {
                if (Integer.toHexString(digest[i] & -1).length() == 1) {
                    stringBuffer.append("0");
                    stringBuffer.append(Integer.toHexString(digest[i] & -1));
                } else {
                    stringBuffer.append(Integer.toHexString(digest[i] & -1));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return stringBuffer.toString();
    }
}
